package gnss

import "fmt"

func YObsSigID2Code(naviSys byte, sigid byte) string {
	if sigid == 0 {
		return fmt.Sprintf("%.2d", sigid)
	}
	sigv := sigid - 1
	if naviSys == SYS_GPS {
		return YOBS_GPS_SIGN_MAP[sigv]
	} else if naviSys == SYS_BD {
		return YOBS_BDS_SIGN_MAP[sigv]
	} else if naviSys == SYS_GAL {
		return YOBS_GAL_SIGN_MAP[sigv]
	} else if naviSys == SYS_GLO {
		return YOBS_GLO_SIGN_MAP[sigv]
	} else if naviSys == SYS_SBS {
		return YOBS_GPS_SIGN_MAP[sigv]
	} else if naviSys == SYS_QZS {
		return YOBS_QZS_SIGN_MAP[sigv]
	} else {
		return "NN"
	}
	return ""
}

func YObsSigId2SigType(navisys byte, sigid byte) byte {
	switch navisys {
	case SYS_BD:
		return YObsSigId2SigType_BDS(sigid)
	case SYS_GPS:
		return YObsSigId2SigType_GPS(sigid)
	case SYS_GLO:
		return YObsSigId2SigType_GLO(sigid)
	case SYS_GAL:
		return YObsSigId2SigType_GAL(sigid)
	}
	return 0
}

func YObsSigId2SigType_BDS(sigid byte) byte {
	switch sigid {
	case YOBS_BDS_SIGN_B1_2I, YOBS_BDS_SIGN_B1_2Q, YOBS_BDS_SIGN_B1_2X:
		return FREQ_BD_BAND_TYPE_B1I
	case YOBS_BDS_SIGN_B3_6I, YOBS_BDS_SIGN_B3_6Q, YOBS_BDS_SIGN_B3_6X:
		return FREQ_BD_BAND_TYPE_B3I
	case YOBS_BDS_SIGN_B2_7I, YOBS_BDS_SIGN_B2_7Q, YOBS_BDS_SIGN_B2_7X:
		return FREQ_BD_BAND_TYPE_B2I
	case YOBS_BDS_SIGN_B2A_5D, YOBS_BDS_SIGN_B2A_5P, YOBS_BDS_SIGN_B2A_5X:
		return FREQ_BD_BAND_TYPE_B2A
	case YOBS_BDS_SIGN_B2B_7D, YOBS_BDS_SIGN_B2B_7P, YOBS_BDS_SIGN_B2B_7Z:
		return FREQ_BD_BAND_TYPE_B2B
	case YOBS_BDS_SIGN_B2AB_8D, YOBS_BDS_SIGN_B2AB_8P, YOBS_BDS_SIGN_B2AB_8X:
		return FREQ_BD_BAND_TYPE_B2AB
	case YOBS_BDS_SIGN_B1C_1D, YOBS_BDS_SIGN_B1C_1P, YOBS_BDS_SIGN_B1C_1X:
		return FREQ_BD_BAND_TYPE_B1C
	}
	return 0
}

/*
*

	    YOBS_GPS_SIGN_L1_1C byte = 2;
		YOBS_GPS_SIGN_L1_1P byte = 3;
		YOBS_GPS_SIGN_L1_1W byte = 4;

		YOBS_GPS_SIGN_L2_2C byte = 8;
		YOBS_GPS_SIGN_L2_2P byte = 9;
		YOBS_GPS_SIGN_L2_2W byte = 10;

		YOBS_GPS_SIGN_L2_2S byte = 15;
		YOBS_GPS_SIGN_L2_2L byte = 16;
		YOBS_GPS_SIGN_L2_2X byte = 17;

		YOBS_GPS_SIGN_L5_5I byte = 22;
		YOBS_GPS_SIGN_L5_5Q byte = 23;
		YOBS_GPS_SIGN_L5_5X byte = 24;

		YOBS_GPS_SIGN_L1_1S byte = 30;
		YOBS_GPS_SIGN_L1_1L byte = 31;
		YOBS_GPS_SIGN_L1_1X byte = 32;
*/
func YObsSigId2SigType_GPS(sigid byte) byte {
	switch sigid {
	case YOBS_GPS_SIGN_L1_1C, YOBS_GPS_SIGN_L1_1P, YOBS_GPS_SIGN_L1_1W:
		return FREQ_GPS_TYPE_L1
	case YOBS_GPS_SIGN_L1_1S, YOBS_GPS_SIGN_L1_1L, YOBS_GPS_SIGN_L1_1X:
		return FREQ_GPS_TYPE_L1
	case YOBS_GPS_SIGN_L2_2C, YOBS_GPS_SIGN_L2_2P, YOBS_GPS_SIGN_L2_2P:
		return FREQ_GPS_TYPE_L2
	case YOBS_GPS_SIGN_L2_2S, YOBS_GPS_SIGN_L2_2L, YOBS_GPS_SIGN_L2_2X, YOBS_GPS_SIGN_L2_2W:
		return FREQ_GPS_TYPE_L2
	case YOBS_GPS_SIGN_L5_5I, YOBS_GPS_SIGN_L5_5Q, YOBS_GPS_SIGN_L5_5X:
		return FREQ_GPS_TYPE_L5
	}
	return 0
}

func YObsSigId2SigType_GLO(sigid byte) byte {
	switch sigid {
	case YOBS_GLO_SIGN_G1_1C, YOBS_GLO_SIGN_G1_1P:
		return FREQ1_GLO_TYPE_G1
	case YOBS_GLO_SIGN_G2_2C, YOBS_GLO_SIGN_G2_2P:
		return FREQ1_GLO_TYPE_G2

	}
	return 0
}

func YObsSigId2SigType_GAL(sigid byte) byte {
	switch sigid {
	case YOBS_GAL_SIGN_E1_1C, YOBS_GAL_SIGN_E1_1X:
		return FREQ_GAL_TYPE_E1
	case YOBS_GAL_SIGN_E5A_5I, YOBS_GAL_SIGN_E5A_5X:
		return FREQ_GAL_TYPE_E5A
	case YOBS_GAL_SIGN_E5B_7I, YOBS_GAL_SIGN_E5B_7X:
		return FREQ_GAL_TYPE_E5B
	}
	return 0
}

/*
*

	ms
*/
func TowDiff(startTow, endTow uint32) uint32 {
	if endTow < startTow {
		return endTow + MILL_SECONDS_PER_WEEK - startTow
	} else {
		return endTow - startTow
	}

}
